package com.caiheng.api.controller.platform;

import com.caiheng.api.rabbitmq.RabbitConfig;
import com.caiheng.api.rabbitmq.RabbitMqSender;
import com.caiheng.api.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping(value ="/rabbitmq")
public class RabbitMQController {
    @Autowired
    private RabbitConfig rabbitConfig;
    private RabbitMqSender rabbitMqSender;

    /**
     * 测试 rabbitmq
     * {"data_type":"cancle_warn","event_id":13,"is_warning":1,"event_id":41}
     * @param requestParam
     * @return
     */
    @PostMapping(value = "/test")
    public Object test(@RequestBody String requestParam) {
        String str = "{\"code\":0}";
        System.out.println("rabbitmq 接收参数: " + requestParam + "      " +  DateUtil.getTime());
        RabbitTemplate rabbitTemplate = rabbitConfig.rabbitTemplate();
        rabbitMqSender = new RabbitMqSender(rabbitTemplate);
        rabbitMqSender.sendRabbitmqDirect("que_order_key",requestParam);
        return str;
    }
}
